package java学习.第09章_异常处理;


import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;

public class B2_异常处理之throws {
    public static void main(String[] args) {


        try {
            读取文件();
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }

    /**
     * 将异常抛给了调用者
     *      子类重写父类的方法，子类的异常 小于等于 父类异常(只适用于编译时异常，运行时异常不影响)
     * @throws FileNotFoundException
     * @throws IOException
     */
    private static void 读取文件() throws FileNotFoundException,IOException {
        File f = new File("file/hello.txt");
        FileInputStream fis = new FileInputStream(f);
        byte[] c = new byte[3];
        int read = 0;
        while ((read = fis.read(c))!=-1){

            System.out.print(new String(c,0,read));
        }
    }


}
